package com.kaisu.blog.application.blog.convert;

import com.kaisu.blog.application.blog.dto.BlogDTO;
import com.kaisu.blog.application.blog.dto.BlogPageDTO;
import com.kaisu.blog.application.user.util.UserUtil;
import com.kaisu.blog.domain.blog.Blog;
import com.kaisu.blog.domain.blog.Like;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author kaisu
 */

@Component
public abstract class BlogApplicationConvertDecorated implements BlogApplicationConvert {
    @Autowired
    private BlogApplicationConvert delegate;

    @Override
    public BlogPageDTO toPageDTO(Blog domain) {
        BlogPageDTO pageDTO = delegate.toPageDTO(domain);
        pageDTO.setLike(domain.getLikes().contains(Like.create(UserUtil.currentUser(), domain)));
        return pageDTO;
    }

    @Override
    public BlogDTO toDTO(Blog domain) {
        BlogDTO dto = delegate.toDTO(domain);
        dto.setLike(domain.getLikes().contains(Like.create(UserUtil.currentUser(), domain)));
        return dto;
    }
}
